<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Manual Test Scripts</title>
  <link type="text/css" rel="stylesheet" href="../mbgdoc/mbgstyle.css"/>
</head>
<body>
<h1>Manual Test Scripts</h1>
<p>This page lists scripts for testing the different parts of the MyBatis Generator
UI.  This information may also be helpful in learning how to use the different parts
of the Eclipse user interface for MyBatis Generator.</p>
<h2>Setup</h2>
<ol>
  <li>Make sure you have access to the HSQLDB JAR file and know where the file is on
      your file system.  You can obtain the JAR from http://hsqldb.org.  The jar
      will probably be on your system in your local Maven repository
      (../.m2/repository/org/hsqldb/..).
  </li>
  <li>Make sure that the new version of the plugin has been built.</li>
</ol>

<h2>Tests</h2>
<p>The following tests are intended to be executed in the order listed.  Some
tests build on items created in previous tests.</p>
<h3>Installation</h3>
<ol>
  <li>Install a fresh version of Eclipse version 4.7.3 (Oxygen 3A) or later.</li>
  <li>Open the fresh Eclipse install, and create a new (empty) workspace</li>
  <li>Configure a local update site to point to the newly generated site
      (Help&gt;Install New Software...)</li>
  <li>Install the feature</li>
  <li>Restart Eclipse</li>
  <li>Verify that the latest version of the feature is listed as installed</li>
</ol>

<h3>Documentation</h3>
<ol>
  <li>Open the Eclipse help (Help&gt;Help Contents)</li>
  <li>Verify that the book "MyBatis Generator User's Guide" appears
      in the contents.</li>
  <li>Verify that every item in the contents points to a valid page,
      and that all pages are referenced in the table of contents.  This is
      especially important if new packages or help pages have been added anywhere.</li>
  <li>Verify that the core MyBatis Generator documentation pages do not show the options
      to show or hide the menu.  These options should be disabled by the style sheet.</li>
  <li>Verify that the latest version of the release notes is shown both in the
      Eclipse UI documentation, and the Core MyBatis Generator documentation.</li>
</ol>

<h3>XML Catalog</h3>
<ol>
  <li>Open Window&gt;Preferences</li>
  <li>Navigate to XML&gt;XML Catalog</li>
  <li>Verify that an XML catalog entry is present for MyBatis Generator</li>
</ol>

<h3>New File Wizard</h3>
<ol>
  <li>Create a new JavaProject called "MBGTest".  Make sure there is a separate source folder
      called <code>src</code></li>
  <li>Add an additional source folder called <code>generatedsrc</code></li>
  <li>Create a new package in the <code>src</code> folder called <code>config</code></li>
  <li>Make a new configuration file:
    <ol type="a">
      <li>Right click on the <code>config</code> package</li>
      <li>Select New&gt;Other&gt;MyBatis&gt;MyBatis Generator Configuration File</li>
      <li>Press Next</li>
      <li>Verify that Location is set to "MBGTest/src/config"</li>
      <li>Verify that File Name is set to "generatorConfig.xml"</li>
      <li>Press Finish</li>
      <li>Verify that an editor opens with a skeleton configuration File</li>
    </ol></li>
    <li>Make a new package in the <code>src</code> folder called <code>base</code></li>
    <li>Add a new class to the <code>base</code> package named <code>BaseModel</code></li>
    <li>Add a <code>private Integer id</code> to <code>BaseModel</code> and generate
        getters and setters.  Then mark the getter and setter <code>final</code>
    </li>
</ol>

<h3>Generate MyBatis Artifacts</h3>
<ol>
  <li>Open an editor on the file "generatorConfig.xml" that you created in the previous test</li>
  <li>Change the contents of the file to the following:
    <pre>

&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;!DOCTYPE generatorConfiguration
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" &gt;
&lt;generatorConfiguration&gt;
  &lt;context id="context1" targetRuntime="MyBatis3Simple" &gt;
    &lt;jdbcConnection driverClass="${driver}"
      connectionURL="jdbc:hsqldb:mem:aname"
      userId="sa" &gt;
    &lt;/jdbcConnection&gt;
    &lt;javaModelGenerator targetPackage="gen.model" targetProject="MBGTest" &gt;
        &lt;!--
        &lt;property name="rootClass" value="base.BaseModel" /&gt;
        --&gt; 
    &lt;/javaModelGenerator&gt;
    &lt;sqlMapGenerator targetPackage="gen.mapper" targetProject="MBGTest" /&gt;
    &lt;javaClientGenerator targetPackage="gen.mapper" targetProject="MBGTest" type="XMLMAPPER" /&gt;
    &lt;table tableName="a" /&gt;
  &lt;/context&gt;

  &lt;context id="context2" targetRuntime="MyBatis3Simple" &gt;
    &lt;connectionFactory type="DEFAULT" &gt;
        &lt;property name="driverClass" value="org.hsqldb.jdbcDriver" /&gt;
        &lt;property name="connectionURL" value="jdbc:hsqldb:mem:aname" /&gt;
        &lt;property name="userId" value="sa" /&gt;
    &lt;/connectionFactory&gt;
    &lt;javaModelGenerator targetPackage="gen.src.model" targetProject="MBGTest/generatedsrc" /&gt;
    &lt;sqlMapGenerator targetPackage="gen.src.mapper" targetProject="MBGTest/generatedsrc" /&gt;
    &lt;javaClientGenerator targetPackage="gen.src.mapper" targetProject="MBGTest/generatedsrc" type="XMLMAPPER" /&gt;
    &lt;table schema="mbgtest" tableName="%" /&gt;
  &lt;/context&gt;
&lt;/generatorConfiguration&gt;
    </pre></li>
    <li>Save the file</li>
    <li>Right click on the file, then take the option "Run As&gt;Run MyBatis Generator"</li>
    <li>Verify that an error dialog is shown with the detail message "Exception getting JDBC Driver"</li>
    <li>Press "OK" to dismiss the dialog</li>
    <li>Create a new file in the "config" package named "create_db.sql"</li>
    <li>Change the contents of the file to the following:
      <pre>
      
drop table a if exists;
drop table mbgtest.b if exists;
drop table mbgtest.b if exists;
drop table mbgtest.c if exists;
drop table mbgtest.d if exists;
drop table mbgtest.e if exists;
drop table mbgtest.f if exists;
drop table mbgtest.g if exists;
drop table mbgtest.h if exists;
drop table mbgtest.i if exists;
drop table mbgtest.j if exists;
drop schema if exists mbgtest;
create schema mbgtest;
create table a (id int not null, description varchar(50), primary key(id));
create table mbgtest.b (id int not null, description varchar(50), primary key(id));
create table mbgtest.c (id int not null, description varchar(50), primary key(id));
create table mbgtest.d (id int not null, description varchar(50), primary key(id));
create table mbgtest.e (id int not null, description varchar(50), primary key(id));
create table mbgtest.f (id int not null, description varchar(50), primary key(id));
create table mbgtest.g (id int not null, description varchar(50), primary key(id));
create table mbgtest.h (id int not null, description varchar(50), primary key(id));
create table mbgtest.i (id int not null, description varchar(50), primary key(id));
create table mbgtest.j (id int not null, description varchar(50), primary key(id));
      </pre>
    </li>
    <li>Open the launch configuration for this new configuration file.  The launch
        configuration should be named MBGTest-generatorConfig.xml</li>
    <li>Alter the launch configuration to run the script before code generation:
      <ul>
        <li>Open the SQL Script tab</li>
        <li>Use the "Workspace..." button to navigate to the new SQL script</li>
        <li>Set "JDBC Driver Class" to "org.hsqldb.jdbcDriver"</li>
        <li>Set "JDBC URL" to "jdbc:hsqldb:mem:aname"</li>
        <li>Set "User ID" to "sa"</li>
        <li>Open the "Classpath" tab</li>
        <li>Add a user entry for the HSQLDB Jar</li>
        <li>Open the environment tab</li>
        <li>Add an environment variable - set "driver" to "org.hsqldb.jdbcDriver"</li>
      </ul>
    </li>
    <li>Run the launch configuration</li>
    <li>Verify that code is generated in the two different source folders.  Code for table "a"
        should be in the "src" folder, code for tables "b" through "j" should be in the
        "generatedsrc" folder.  Verify that there are no compilation errors or warnings.</li>
</ol>

<h3>Java File Merger</h3>
<ol>
  <li>Open the Java file <code>gen.model.A.java</code> in the "src" folder</li>
  <li>Note the time of generation of the file from one of the <code>@mbg.generated</code> comments</li>
  <li>Add a private field of any type called <code>mergetest</code> and generate a getter and setter
      for the field.</li>
  <li>Save and close the file</li>
  <li>Right click on the configuration file from the last test, and then
      take the option "Run As&gt;Run MyBatis Generator"</li>
  <li>Verify that the progress bar is reasonably accurate</li>
  <li>Open the Java file <code>gen.model.A.java</code> in the "src" folder</li>
  <li>Verify that the time of generation is later than the time noted above</li>
  <li>Verify that the field <code>mergetest</code>, and its getter and setter remain
    in the file (they will have been moved to the bottom of the file)</li>
</ol>

<h3>Adventures with Rootclass</h3>
<ol>
  <li>Open the configuration file from the last test.</li>
  <li>Uncomment the "rootClass" property line</li>
  <li>Save and close the file</li>
  <li>Right click on the configuration file, and then
      take the option "Run As&gt;Run MyBatis Generator"</li>
  <li>Verify that <code>gen.model.A</code> now extends <code>BaseModel</code>. You should not have needed to
      alter the launch configuration classpath - the launch configuration automatically adds the project
      to the classpath of the generator.</li>
  <li>Also verify that there are no errors in <code>gen.model.A</code> - the generator
     should not have generated a get and set method that override the final
     methods in the base class</li>
  <li>Re open the configuration file.</li>
  <li>Re comment the "rootClass" property line</li>
  <li>Save and close the file</li>
  <li>Right click on the configuration file, and then
      take the option "Run As&gt;Run MyBatis Generator"</li>
  <li>Verify that <code>gen.model.A</code> doesn't extend anything.  There will be one
      warning in the file related to an unused import (the Java merger does not reconcile all
      imports).  Delete the import and verify that there are no other errors in the
      workspace.  Also, verify that the field <code>mergetest</code> and its
      associated getter and setter still exist, and that the id field and its
      getter and setter are back in the class.</li>
</ol>

<h3>Ant Build</h3>
<ol>
  <li>Create a new file <code>build.xml</code> in the "MBGTest/src/config" package.</li>
  <li>Change the contents of the new file to the following:
    <pre>
    
&lt;project default="runMyBatisGenerator"&gt;
  &lt;target name="runMyBatisGenerator"&gt;
    &lt;eclipse.convertPath resourcepath="MBGTest/src/config/create_db.sql"
                         property="theScriptPath"/&gt;
    &lt;sql driver="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:mem:aname"
            userid="sa" password="" src="${theScriptPath}"/&gt;
    &lt;eclipse.convertPath resourcepath="MBGTest/src/config/generatorConfig.xml"
                         property="thePath"/&gt;
    &lt;mybatis.generate configfile="${thePath}" /&gt;
  &lt;/target&gt;
&lt;/project&gt;
    </pre>
  </li>
  <li>Save and close the file.</li>
  <li>Delete the Java class <code>gen.src.model.A</code>.  There will now be errors in the
      workspace.</li>
  <li>Right click on the new <code>build.xml</code> file, then select the
      menu option "Run As&gt;Ant Build...".  You should see the Ant launch configuration
      dialog open.</li>
  <li>Select the "JRE" tab, then select the "Run in the same JRE as the workspace" radio
      button.</li>
  <li>Press the "Run" button</li>
  <li>You should see an error in the progress window stating "Class not found: JDBC Driver...".</li>
  <li>Right click on the new <code>build.xml</code> file, then select the
      menu option "Run As&gt;Ant Build...".  You should see the Ant launch configuration
      dialog open.</li>
  <li>Select the "Classpath" tab, then add the HSQLDB driver to "User Entries"</li>
  <li>Press the "Run" button</li>
  <li>After MyBatis Generator runs, you should see a "BUILD SUCCESSFUL" message.
      You may see build warnings related to log4j if it is not installed in your Eclipse
      distribution.  You can safely ignore these warnings.
  </li>
  <li>Verify that the workspace errors are gone.</li>
</ol>

</body>
</html>
